package com.ruoyi.match.service.impl;


import com.ruoyi.match.domain.MatchUserEquipment;
import com.ruoyi.match.exception.CustomException;
import com.ruoyi.match.exception.CustomExceptionType;
import com.ruoyi.match.mapper.MatchEquipmentMapper;
import com.ruoyi.match.mapper.MatchUserEquipmentMapper;
import com.ruoyi.match.mapper.MatchUserMapper;
import com.ruoyi.match.service.MatchUserEquipmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author WYC
 * @since 2021-03-18
 */
@Service
@Slf4j
public class MatchUserEquipmentServiceImpl implements MatchUserEquipmentService {


    @Autowired
    private MatchUserEquipmentMapper matchUserEquipmentMapper;
    @Autowired
    private MatchUserMapper matchUserMapper;
    @Autowired
    private MatchEquipmentMapper equipmentMapper;
    @Override
    public List<MatchUserEquipment> selectAll(String phone,String equipmentId) {
        return matchUserEquipmentMapper.selectAll(phone,equipmentId);
    }

    @Transactional
    @Override
    public void bangding(String phone, String equipmentId) {
       int x= matchUserMapper.updateStatus(phone,2);
       int y= equipmentMapper.updateMatchUser(equipmentId,phone);
       int z=matchUserEquipmentMapper.delete(equipmentId);
       if(x<1||y<1||z<1){
           throw new CustomException(CustomExceptionType.SYSTEM_ERROR, "绑定失败");
       }
    }

    @Override
    public void jujue(String phone, String equipmentId) {
        int x= matchUserMapper.updateStatus(phone,0);
        int y=matchUserEquipmentMapper.delete(equipmentId);
        if(x<1||y<1){
            throw new CustomException(CustomExceptionType.SYSTEM_ERROR, "拒接绑定失败");
        }
    }
}
